﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessBoard
{
    class Frame : Shape
    {
        public FrameSymbol FrameSymbols { get; set; }

        public Frame(Point topLeft, int width, int height,
            ConsoleColor foregroundColor, ConsoleColor backgroundColor, FrameSymbol frameSymbols)
            : base(topLeft, width, height, foregroundColor, backgroundColor)
        {
            this.FrameSymbols = frameSymbols;
        }

        public Frame() 
            : this(new Point(0, 0), 0, 0, 0, 0, new FrameSymbol())
        { }

        public override void Draw(Point topLeft, ConsoleColor backgroundColor)
        {
            Console.SetCursorPosition(topLeft.X, topLeft.Y);
            Console.BackgroundColor = backgroundColor;
            Console.ForegroundColor = this.ForegroundColor;
            DrawHorizontalLine(this.FrameSymbols.TopLeftCorner, this.FrameSymbols.TopRightCorner);

            DrawVerticleLine(topLeft.X);

            DrawHorizontalLine(this.FrameSymbols.BottomLeftCorner, this.FrameSymbols.BottomRightCorner);
        }

        private void DrawHorizontalLine(char left, char right)
        {
            Console.Write(left);
            Console.Write(new string(this.FrameSymbols.HorBorder, this.Width - 2));
            Console.WriteLine(right);
        }

        private void DrawVerticleLine(int leftPosition)
        {
            for (int i = 0; i < this.Height - 2; i++)
            {
                Console.CursorLeft = leftPosition;
                Console.Write(this.FrameSymbols.VertBorder);
                Console.CursorLeft = leftPosition + this.Width - 1;
                Console.WriteLine(this.FrameSymbols.VertBorder);
            }
        }
    }
}
